#include "proxy/encry/encrybase.h"

namespace proxy{


  void EncryData(char* data, int size, unsigned key){
    for (int i = 0; i < size; i++){
      unsigned char t = data[i] ^ key;
      t = (t >> 4) | (t << 4);
      data[i] = t;
    }
  }

  void DecodeData(char* data, int size, unsigned key){
    for (int i = 0; i < size; i++){
      unsigned char t = data[i];
      t = (t >> 4) | (t << 4);
      data[i] = t ^ key;
    }
  }
////////////////////////////////////////////////////////////////////////////////
  const char RANDOM_SET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ+=_/;";
  const int MAX_RANDOM_SET_SIZE = 40;
  std::string RandomString(int size){
    std::string random_str;
    for (int i = 0; i < size; i++){
      random_str.push_back(RANDOM_SET[rand() % MAX_RANDOM_SET_SIZE]);
    }
    return random_str;
  }

  char AddRandomChar(std::string &str, int size){
    char first = -1;
    for (int i = 0; i < size; i++){
      if (first == -1){
        first = RANDOM_SET[rand() % MAX_RANDOM_SET_SIZE];
        str.push_back(first);
      }
      else{
        str.push_back(RANDOM_SET[rand() % MAX_RANDOM_SET_SIZE]);
      }
    }
    return first;
  }
}